<?php
include_once('common/header.php');
if($AppUI->id <=0 ){
	$this->_redirect(HOST_BACKEND);
}
$strPasswordOld 	= $objRequest->getParam('ppassword_old', '');
$strPassword 		= $objRequest->getParam('ppassword', '');
$strPasswordConf 	= $objRequest->getParam('ppassword_confirm', '');
$strUsername		= $objRequest->getParam('pusername', '');
$intError			= 0;
$arrError			= null;
if(trim($strPasswordOld) == '') $arrError[] = $arrLocale['password_old_required'];
if(trim($strPassword) == '') $arrError[] = $arrLocale['password_required'];
if($strPassword != '' && (strlen($strPassword) < 5 || strlen($strPassword) > 30)) $arrError[] = $arrLocale['password_minlength'];
if($strPassword != '' && $strPassword != $strPasswordConf) $arrError[] = $arrLocale['password_notmatch'];
if($intError == 0) {
	if(isset($_SESSION['CHANGEPW_ERROR'])) unset($_SESSION['CHANGEPW_ERROR']);
	$objAdmin			= new Admin();
	$objAdmin->updatePassword(0, $AppUI->id, $AppUI->username, md5($strPassword));	
	Ecore_Function::setMsg($arrMessage['change_pw']);
	$this->_redirect(isset($_SESSION[SESSION_BACKURL]) ? $_SESSION[SESSION_BACKURL] : HOST_BACKEND);
}
if(isset($arrError)) {
	$_SESSION['CHANGEPW_ERROR']	= $arrError[$intError];	
}
$this->_redirect(isset($_SESSION[SESSION_BACKURL]) ? $_SESSION[SESSION_BACKURL] : HOST_BACKEND . 'index/changepw');
